#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>




int main(){

char buffer[256];
char param[10];
int pid;
int status=-1;
int pidhijo;

printf("Joc de proves modul 2(PROSO)\n");
printf("Comenza el joc de proves del pid: ");

pid=getpid();
pidhijo=fork();
if(pidhijo==0){

	pidhijo=fork();
	if(pidhijo==0){
 	     sprintf(param," \npid=%d\n",pid);
	     printf("\n pidhijohijo%d\n",getpid());
	     fflush(stdout);
		//pause();
	     execlp("insmod","insmod","mymodule.ko",param,'\0');
	     exit(0);
	}
	   wait(&status);
 	    
	   printf("\n pid hijo%d\n",getpid());
	   fflush(stdout);
	   execlp("insmod","insmod","mymodule2.ko",'\0');

}

else{
	wait(&status);

write(1,"write	:\n",9);
write(1,"write :\n",8);
write(1,"write :\n",8);

open(4,1);
close(1);


void **pila_hijo;
pila_hijo = malloc(1000);
//clone(cloneando,pila_hijo, CLONE_VM|CLONE_FILES, NULL);


lseek (4, 1, SEEK_SET);
lseek(2,1,0);

pidhijo=fork();
	if(pidhijo==0){
 	     sprintf(param,"pid=%d\n",pid);
	     printf("\n pidhijohijazooooooo%d\n",getpid());
	     fflush(stdout);
		//pause();
	     execlp("rmmod","rmmod","mymodule2.ko",'\0');
	     exit(0);
	}


execlp("rmmod","rmmod","mymodule.ko",'\0');

}
}















     
